import { http } from "@/utils/http";

export type FinancialRecord = {
  id: number;
  user_id?: number;
  order_id?: number;
  type: string;
  amount: number;
  description?: string;
  status: number;
  created_at: string;
  updated_at: string;
};

export type FinancialRecordResponse = {
  success: boolean;
  code: number;
  message: string;
  data: FinancialRecord;
};

export type FinancialRecordListResponse = {
  success: boolean;
  code: number;
  message: string;
  data: FinancialRecord[];
  pagination: {
    page: number;
    page_size: number;
    total: number;
    total_page: number;
  };
};

export type PaginationParams = {
  page?: number;
  page_size?: number;
};

/** 创建财务记录 */
export const createFinancialRecord = (data: Partial<FinancialRecord>) => {
  return http.request<FinancialRecordResponse>("post", "/finance/record", { data });
};

/** 获取财务记录列表 */
export const getFinancialRecords = (params?: PaginationParams) => {
  return http.request<FinancialRecordListResponse>("get", "/finance/record", { params });
};

/** 根据用户ID获取财务记录列表 */
export const getFinancialRecordsByUserId = (id: number, params?: PaginationParams) => {
  return http.request<FinancialRecordListResponse>("get", `/finance/record/user/${id}`, { params });
};

/** 获取财务记录详情 */
export const getFinancialRecordById = (id: number) => {
  return http.request<FinancialRecordResponse>("get", `/finance/record/${id}`);
};

/** 更新财务记录 */
export const updateFinancialRecord = (id: number, data: Partial<FinancialRecord>) => {
  return http.request<FinancialRecordResponse>("put", `/finance/record/${id}`, { data });
};

/** 删除财务记录 */
export const deleteFinancialRecord = (id: number) => {
  return http.request("delete", `/finance/record/${id}`);
};